package top.xqf.homework.service.impl;

import org.springframework.stereotype.Service;
import top.xqf.homework.base.BaseResult;
import top.xqf.homework.dao.TbYsArmsDAO;
import top.xqf.homework.entity.TbYsArms;
import top.xqf.homework.service.ArmsService;

import java.util.List;

@Service
public class ArmsServiceImpl implements ArmsService {
    private final TbYsArmsDAO tbYsArmsDAO;

    public ArmsServiceImpl(TbYsArmsDAO tbYsArmsDAO) {
        this.tbYsArmsDAO = tbYsArmsDAO;
    }


    @Override
    public BaseResult<List<TbYsArms>> query(TbYsArms tbYsArms) throws Exception{
        BaseResult<List<TbYsArms>> result=new BaseResult<>();
        result.setCode(200);
        result.setSuccess(true);
        result.setMessage("");
        result.setData(tbYsArmsDAO.query(tbYsArms));
        return result;
    }


    @Override
    public BaseResult<TbYsArms> add(TbYsArms tbYsArms) throws Exception{
        BaseResult<TbYsArms> result=new BaseResult<>();
        int n=tbYsArmsDAO.add(tbYsArms);
        result.setCode(n==1?200:500);
        result.setSuccess(n==1);
        result.setMessage(n==1?"添加成功":"添加失败");
        result.setData(tbYsArms);
        return result;
    }

    @Override
    public BaseResult<TbYsArms> update(TbYsArms tbYsArms) throws Exception{
        BaseResult<TbYsArms> result=new BaseResult<>();
        int n=tbYsArmsDAO.update(tbYsArms);
        result.setCode(n==1?200:500);
        result.setSuccess(n==1);
        result.setMessage(n==1?"修改成功":"修改失败");
        result.setData(tbYsArms);
        return result;
    }


    @Override
    public BaseResult<TbYsArms> delete(TbYsArms tbYsArms) throws Exception{
        BaseResult<TbYsArms> result=new BaseResult<>();
        int n=tbYsArmsDAO.delete(tbYsArms);
        result.setCode(n==1?200:500);
        result.setSuccess(n==1);
        result.setMessage(n==1?"删除成功":"删除失败");
        result.setData(tbYsArms);
        return result;
    }
}
